package com.ksd1.notes;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.view.MenuItem;

/**
 * 公共父类
 */
public abstract class BaseActivity extends AppCompatActivity {
    private static Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = getApplicationContext();
        //初始化变量、视图、加载数据
        initVariables();
        initViews(savedInstanceState);
        loadData();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
            default:
                break;
        }
        return true;
    }

    public static Context getContext(){
        return context;
    }
    //初始化变量
    protected abstract void initVariables();

    //初始化视图
    protected abstract void initViews(Bundle savedInstanceState);

    //初始化数据
    protected abstract void loadData();
}